package com.sise.bl.utils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.UUID;

//生成邮箱验证 激活码 使用的随机数
public class RandomUtils {
	//当前时间 + 随机数
	public static String createActive(){
		
		return getTime()+Integer.toHexString(new Random().nextInt(900)+100);
	}
	public static String getTime(){
		return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime());
	}
	//生成订单编号
	public static String createOrderId(){
		return getTime();
	}

	public static String newFileName(String filename){
		return UUID.randomUUID().toString().replaceAll("-","")+"_"+filename;
	}
	//生成二级、三级目录
	public static String newFilePath(String basepath,String filename){
		int hashCode = filename.hashCode();
		int path1 = hashCode & 15;//二级目录  与运算 0~15
		int path2 = (hashCode>>4) & 15;//三级目录  0~15
		String newPath = basepath+"\\"+path1+"\\"+path2;
		File file = new File(newPath);
		if(!file.exists()){
			file.mkdirs();
		}
		return newPath;
	}
}
